package com.jingdianjichi.auth.domain.service.impl;

import com.jingdianjichi.auth.common.enums.IsDeletedEnum;
import com.jingdianjichi.auth.domain.convert.AuthRoleConverter;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRole;
import com.jingdianjichi.auth.infra.basic.service.AuthRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    AuthRoleService authRoleService;
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConverter.INSTANCE.converterBoToAuthUser(authRoleBO);
        authRole.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());

        return authRoleService.insert(authRole)>0;
    }

    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConverter.INSTANCE.converterBoToAuthUser(authRoleBO);
        Integer update = authRoleService.update(authRole);
        return update>0;
    }

    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConverter.INSTANCE.converterBoToAuthUser(authRoleBO);
        authRole.setIsDeleted(IsDeletedEnum.DELETED.getCode());

        return authRoleService.update(authRole)>0;
    }
}
